/*     */ package com.hs.activation.service.impl;
/*     */ 
/*     */ import com.baomidou.mybatisplus.core.conditions.Wrapper;
/*     */ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
/*     */ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
/*     */ import com.baomidou.mybatisplus.core.metadata.IPage;
/*     */ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/*     */ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/*     */ import com.hs.activation.common.utils.BaseUtil;
/*     */ import com.hs.activation.common.utils.CodeUtil;
/*     */ import com.hs.activation.common.utils.DateUtil;
/*     */ import com.hs.activation.common.utils.JwtUtil;
/*     */ import com.hs.activation.common.utils.MailUtil;
/*     */ import com.hs.activation.dataemum.DeviceTypeEnum;
/*     */ import com.hs.activation.dto.ActivationDTO;
/*     */ import com.hs.activation.dto.ActivationGroupDTO;
/*     */ import com.hs.activation.entity.Activation;
/*     */ import com.hs.activation.entity.ActivationLog;
/*     */ import com.hs.activation.entity.User;
/*     */ import com.hs.activation.mapper.ActivationMapper;
/*     */ import com.hs.activation.service.IActivationLogService;
/*     */ import com.hs.activation.service.IActivationService;
/*     */ import com.hs.activation.service.IUserService;
/*     */ import com.hs.activation.vo.ActivationVO;
/*     */ import com.hs.activation.vo.AlertActionExpirationTimeVO;
/*     */ import com.hs.activation.vo.ErpInfoVO;
/*     */ import java.lang.invoke.SerializedLambda;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import org.springframework.beans.BeanUtils;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.scheduling.annotation.Scheduled;
/*     */ import org.springframework.stereotype.Service;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Service
/*     */ public class ActivationServiceImpl
/*     */   extends ServiceImpl<ActivationMapper, Activation>
/*     */   implements IActivationService
/*     */ {
/*     */   @Autowired
/*     */   IActivationLogService activationLogService;
/*     */   @Autowired
/*     */   MailUtil mailUtil;
/*     */   @Autowired
/*     */   IUserService userService;
/*     */   
/*     */   public boolean save(ActivationVO activationVO) {
/*  52 */     Activation activation = new Activation();
/*  53 */     BeanUtils.copyProperties(activationVO, activation);
/*  54 */     List<String> emailList = this.userService.getEmailList();
/*  55 */     User user = (User)this.userService.getById(activationVO.getAttendantId());
/*  56 */     if (user != null) {
/*  57 */       activation.setAttendant(user.getUserName());
/*     */     }
/*     */     
/*  60 */     for (String email : emailList) {
/*  61 */       this.mailUtil.sendMail(email, "新增客户信息", "新增客户" + activation.getCompanyName() + "的" + activation
/*  62 */           .getSystemVersion() + "激活");
/*     */     }
/*     */     
/*  65 */     return save(activation);
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public boolean save(Activation activation) {
/*  71 */     activation.setCreateTime(new Date(System.currentTimeMillis()));
/*  72 */     String activationCode = CodeUtil.generateActivation(activation.getComputerCode(), Long.valueOf(System.currentTimeMillis()), activation
/*  73 */         .getExpirationTime());
/*  74 */     activation.setActivationCode(activationCode);
/*  75 */     return retBool(Integer.valueOf(((ActivationMapper)this.baseMapper).insert(activation)));
/*     */   }
/*     */ 
/*     */   
/*     */   public boolean update(ActivationVO activationVO) {
/*  80 */     Activation activation = (Activation)getById(activationVO.getId());
/*  81 */     if (activation != null) {
/*  82 */       Date oldExpiration = activation.getExpirationTime();
/*  83 */       BeanUtils.copyProperties(activationVO, activation);
/*  84 */       User user = (User)this.userService.getById(activationVO.getAttendantId());
/*  85 */       if (user != null) {
/*  86 */         activation.setAttendant(user.getUserName());
/*     */       }
/*  88 */       activation.setLastModifyUserId(JwtUtil.getCurrentUserId());
/*  89 */       activation.setLastModifyTime(new Date(System.currentTimeMillis()));
/*  90 */       if (activationVO.getExpirationTime() != oldExpiration) {
/*  91 */         ActivationLog activationLog = new ActivationLog();
/*  92 */         activationLog.setActivationId(activation.getId());
/*  93 */         activationLog.setModifyTime(new Date(System.currentTimeMillis()));
/*  94 */         activationLog.setNewExpirationTime(activationVO.getExpirationTime());
/*  95 */         activationLog.setOldExpirationTime(oldExpiration);
/*  96 */         activationLog.setModifyUserId(JwtUtil.getCurrentUserId());
/*  97 */         String activationCode = CodeUtil.generateActivation(activation.getComputerCode(), Long.valueOf(System.currentTimeMillis()), activation.getExpirationTime());
/*  98 */         activation.setActivationCode(activationCode);
/*  99 */         activationLog.setActivationCode(activationCode);
/* 100 */         activationLog.setDueDays(DateUtil.getDateDiffer(activationLog.getNewExpirationTime(), new Date(System.currentTimeMillis())));
/* 101 */         sendEmail(activation, oldExpiration);
/* 102 */         this.activationLogService.save(activationLog);
/*     */       } 
/* 104 */       return updateById(activation);
/*     */     } 
/* 106 */     return false;
/*     */   }
/*     */ 
/*     */   
/*     */   public String getActivationCodeByErpInfo(ErpInfoVO erpInfo) {
/* 111 */     Activation activation = findByErpInfo(erpInfo);
/* 112 */     if (activation == null) {
/* 113 */       activation = new Activation();
/* 114 */       activation.setExpirationTime(DateUtil.getBeforeOrAfterDate(new Date(System.currentTimeMillis()), 15));
/* 115 */       BeanUtils.copyProperties(erpInfo, activation);
/* 116 */       User user = this.userService.findByUserName(erpInfo.getAttendant());
/* 117 */       if (user != null) {
/* 118 */         activation.setAttendantId(user.getId());
/*     */       }
/* 120 */       save(activation);
/* 121 */       List<String> emailList = this.userService.getEmailList();
/* 122 */       for (String email : emailList) {
/* 123 */         this.mailUtil.sendMail(email, "激活申请", activation.getCompanyName() + "申请激活" + activation.getCompanyName());
/*     */       }
/*     */     } 
/* 126 */     LambdaUpdateWrapper<Activation> updateWrapper = new LambdaUpdateWrapper();
/* 127 */     updateWrapper.set(Activation::getLastPostTime, new Date(System.currentTimeMillis()));
/* 128 */     update((Wrapper)updateWrapper);
/* 129 */     return activation.getActivationCode();
/*     */   }
/*     */ 
/*     */   
/*     */   public Activation findByErpInfo(ErpInfoVO erpInfo) {
/* 144 */     return null;
/*     */   }
/*     */   
/*     */   public List<ActivationDTO> listDTO(String key, Integer state) {
/*     */
/* 207 */     return null;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private LambdaQueryWrapper<Activation> queryConstructor(String key, Integer state) {
/* 216 */
/* 227 */     return null;
/*     */   }
/*     */   private LambdaQueryWrapper<Activation> queryConstructor(String key, Integer state, String username) {
/* 230 */
/* 244 */     return null;
/*     */   }
/*     */   
/*     */   public IPage<ActivationDTO> pageDTO(Page<Activation> page, String key, Integer state) {
/* 248 */     LambdaQueryWrapper<Activation> queryWrapper = queryConstructor(key, state);
/* 249 */     IPage<Activation> pageList = page((IPage)page, (Wrapper)queryWrapper);
/* 250 */     List<ActivationDTO> result = new ArrayList<>();
/* 251 */     List<User> users = this.userService.list();
/* 252 */     pageList.getRecords().forEach(t -> {
/*     */           ActivationDTO activationDTO = actionEntityToDTO(users, t);
/*     */           result.add(activationDTO);
/*     */         });
/* 256 */     Page page1 = new Page();
/* 257 */     BeanUtils.copyProperties(pageList, page1);
/* 258 */     page1.setRecords(result);
/* 259 */     return (IPage<ActivationDTO>)page1;
/*     */   }
/*     */   
/*     */   private ActivationDTO actionEntityToDTO(List<User> users, Activation action) {
/* 263 */     ActivationDTO activationDTO = new ActivationDTO();
/* 264 */     BeanUtils.copyProperties(action, activationDTO);
/* 265 */     activationDTO.setOnline(DateUtil.judgmentDate(action.getLastPostTime(), new Date(System.currentTimeMillis())));
/* 266 */     users.stream().filter(s -> s.getId().equals(action.getLastModifyUserId())).findFirst()
/* 267 */       .ifPresent(user -> activationDTO.setLastModifyUser(user.getUserName()));
/* 268 */     return activationDTO;
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public List<Activation> getGroupList() {
/* 274 */     List<ActivationGroupDTO> result = new ArrayList<>();
/* 275 */     LambdaQueryWrapper<Activation> query = new LambdaQueryWrapper();
/* 276 */     query.eq(Activation::getDeviceType, DeviceTypeEnum.GROUP.index);
/* 277 */     return list((Wrapper)query);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public boolean setState(Integer id, Integer state) {
/* 284 */     return false;
/*     */   }
/*     */ 
/*     */   
/*     */   public ActivationDTO updateExpirationTime(AlertActionExpirationTimeVO expirationTimeVO) {
/* 292 */     Activation activation = (Activation)getById(expirationTimeVO.getId());
/* 293 */     List<User> users = this.userService.list();
/* 294 */     if (activation != null) {
/* 295 */       Date oldExpiration = activation.getExpirationTime();
/* 296 */       activation.setExpirationTime(expirationTimeVO.getExpirationTime());
/* 297 */       activation.setLastModifyUserId(JwtUtil.getCurrentUserId());
/* 298 */       activation.setLastModifyTime(new Date(System.currentTimeMillis()));
/* 299 */       String activationCode = CodeUtil.generateActivation(activation.getComputerCode(), Long.valueOf(System.currentTimeMillis()), activation.getExpirationTime());
/* 300 */       activation.setActivationCode(activationCode);
/* 301 */       ActivationLog activationLog = new ActivationLog();
/* 302 */       activationLog.setActivationId(activation.getId());
/* 303 */       activationLog.setModifyTime(new Date(System.currentTimeMillis()));
/* 304 */       activationLog.setNewExpirationTime(activation.getExpirationTime());
/* 305 */       activationLog.setOldExpirationTime(oldExpiration);
/* 306 */       activationLog.setModifyUserId(JwtUtil.getCurrentUserId());
/* 307 */       activationLog.setActivationCode(activationCode);
/* 308 */       activationLog.setReasons(expirationTimeVO.getReasons());
/* 309 */       activationLog.setDueDays(DateUtil.getDateDiffer(new Date(), activationLog.getNewExpirationTime()));
/* 310 */       sendEmail(activation, oldExpiration);
/* 311 */       this.activationLogService.save(activationLog);
/* 312 */       updateById(activation);
/* 313 */       return actionEntityToDTO(users, activation);
/*     */     } 
/*     */     
/* 316 */     return new ActivationDTO();
/*     */   }
/*     */   
/*     */   private void sendEmail(Activation activation, Date oldExpiration) {
/* 320 */     List<String> emailList = this.userService.getEmailList();
/* 321 */     for (String email : emailList) {
/* 322 */       this.mailUtil.sendMail(email, "客户激活时间变更", activation.getCompanyName() + "的" + activation.getCompanyName() + "激活时间从" + activation.getSystemVersion() + "变更为" + 
/* 323 */           DateUtil.dateToLongString(oldExpiration));
/*     */     }
/*     */     
/* 326 */     if (!BaseUtil.isEmpty(activation.getCompanyEmail())) {
/* 327 */       this.mailUtil.sendMail(activation.getCompanyEmail(), "郑州华砂信息技术有限公司[系统激活]", "尊敬的" + activation
/* 328 */           .getCompanyName() + "客户系统负责人" + activation
/* 329 */           .getAttendant() + "，您好！您的" + activation.getSystemVersion() + " -" + SysType(activation.getDeviceType().intValue()) + "系统使用授权到期日期由" + 
/* 330 */           DateUtil.dateToLongString(oldExpiration) + "变更为" + 
/* 331 */           DateUtil.dateToLongString(activation.getExpirationTime()) + "，系统当前使用剩余天数为" + 
/*     */           
/* 333 */           DateUtil.getDateDiffer(activation.getExpirationTime(), new Date(System.currentTimeMillis())) + "，您系统的最新激活码为" + activation
/* 334 */           .getActivationCode());
/*     */     }
/*     */   }
/*     */   
/*     */   private String SysType(int type) {
/* 339 */     String typeName = "";
/* 340 */     switch (type) {
/*     */       case 0:
/* 342 */         typeName = "ERP 电脑版";
/*     */         break;
/*     */       case 1:
/* 345 */         typeName = "ERP 手机App";
/*     */         break;
/*     */       case 2:
/* 348 */         typeName = "工地端App";
/*     */         break;
/*     */       case 3:
/* 351 */         typeName = "司机端App";
/*     */         break;
/*     */       case 4:
/* 354 */         typeName = "供应商端App";
/*     */         break;
/*     */       case 5:
/* 357 */         typeName = "经销商端App";
/*     */         break;
/*     */     } 
/* 360 */     return typeName;
/*     */   }
/*     */ 
/*     */   
/*     */   @Scheduled(cron = "0 30 8 * * ?")
/*     */   public void checkExpirationTime() {
/* 366 */     List<Activation> list = list();
/* 367 */     List<String> emailList = this.userService.getEmailList();
/* 368 */     list.forEach(activation -> {
/*     */           Double dateDiffer = DateUtil.getDateDiffer(new Date(), activation.getExpirationTime());
/*     */           if (dateDiffer.doubleValue() <= 4.0D)
/*     */             for (String email : emailList)
/*     */               this.mailUtil.sendMail(email, "客户系统即将到期", activation.getCompanyName() + activation.getCompanyName() + " - " + activation.getSystemVersion() + "即将到期！到期时间" + SysType(activation.getDeviceType().intValue()));  
/*     */         });
/*     */   }
/*     */ }


/* Location:              C:\Users\yzc\Desktop\新建文件夹 (3)\activation-0.0.16.jar!\BOOT-INF\classes\com\hs\activation\service\impl\ActivationServiceImpl.class
 * Java compiler version: 16 (60.0)
 * JD-Core Version:       1.1.3
 */